//
//  GHHomeViewController.swift
//  GHWeibo
//
//  Created by LGH on 2017/8/3.
//  Copyright © 2017年 LGH. All rights reserved.
//

import UIKit


class GHHomeViewController: GHBaseViewController {

    lazy var statusViewModel = GHStatusViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view

    }
    
    override func loadData() {
        
        //tableView?.setContentOffset(CGPoint(x: 0, y: -64), animated: true)
        
        
        statusViewModel.loadData(isPullup: isPullUp) { (isSuccess) in
            
            print("开始加载数据")
            DispatchQueue.main.async {
 
                self.isPullUp = false
                self.tableView?.reloadData()
                print("加载完成")
                self.refreshCtl?.endRefreshing()
            }
        }

    }
    
    override func setupTableView() {
        super.setupTableView()
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(titile: "好友", normalColor: .darkGray, higlightedColor: .orange, target: self, action: #selector(showFriedns))
        
//        tableView?.contentInset = UIEdgeInsets(
//            top: 0,
//            left: 0,
//            bottom: 64,
//            right: 0)
    }
    
}

extension GHHomeViewController {
    
    func showFriedns() {
        
        let vc = GHDemoViewController()

        navigationController?.pushViewController(vc, animated: true)
    }
}

// MARK: - tableView数据源和代理方法
extension GHHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return statusViewModel.statusList.count
        
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = statusViewModel.statusList[indexPath.row].text
        return cell
    }
    
    
}
